#!/usr/local/bin/bash
#
# set up the enviroment
export PATH=/bin
export PATH=/usr/local/bin:$PATH
export PATH=/usr/local/jpeg-6b/bin:$PATH
export PATH=/usr/local/pbmplus/bin:$PATH
export PATH=/usr/ucb:$PATH
export NULL=/dev/null
export TEMP=/tmp/`date | tr ' ' _ | tr : _`
#
# check for noindex file
if (test -f noindex);then 
	echo "Error: Remove the noindex file before indexing this directory";
	exit;
fi
#
# unpack the mime files, delete the mimes as we go through them
for x in `ls *.mime 2> $NULL`; do munpack $x; rm $x; done
#
# New 8-12-99 Zap the case to all lower case...
for x in `ls *[A-Z]* 2> $NULL`;do mv $x `echo $x|tr A-Z a-z`; done
#
# New 8-12-99 Delete dupe files with foo.jpg.1 syntax
for x in `ls *.*.[0-9] 2> $NULL`;do rm $x; done
#
# make the thumbnails
for x in `ls *.jpg | grep -v ___ 2> $NULL`;do 
	if (! test -f ___$x); then
		if (! djpeg -fast -pnm $x | pnmscale -ysize 130 | cjpeg -progressive > "___"$x); then
			echo "Error: $x is corrupt, Deleating...";
			rm $x;
			rm ___$x;
		fi
	fi
done
#
# delete the description files
for x in `ls *.desc 2> $NULL`;do rm $x;done
#
# begin the page creation here !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#
# Title Stuff
echo "<h1><center>$1</h1></center>" > index.html
echo "<hr>" >> index.html
#
# Index the jpeg images
for x in `ls *.jpg|egrep -v 'index.html|___' 2> $NULL`;do 
	echo "<a href=\""$x\""><img src=\"___"$x"\"></a><p><h3>`rdjpgcom $x`</h3><br>" >>index.html;
echo "<hr>" >> index.html
done
#
# Index the directories
for x in `ls -F | grep / | cut -d / -f1 2> $NULL`;do
	if (test -f $x.dir);then
		y=`cat $x.dir`;
	else
		y=$x;
	fi
#
	if (test -f $x.gif);then
		z=$x.gif;
	else
		cp /etc/defaultdir.gif .;
		z="defaultdir.gif";
	fi
#
	echo "<a href=\""$x\""><img src=\"$z\"></a><p><h3>$y</h3><br>" >>index.html;
echo "<hr>" >> index.html
done
#
echo "<hr>" >> index.html
#
# check for tag.html file and add it to the end of the index
if (test -f tag.html);then
	cat index.html tag.html > $TEMP
	cp $TEMP index.html
	rm $TEMP
fi
